﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SEO.Entity;
using System.Data.SqlClient;
using System.Data;

namespace SEO.Business
{
    /// <summary>
    /// 配置信息
    /// </summary>
    public class BisSysConfig
    {
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <returns></returns>
        public SysConfig GetSysConfig()
        {
            SqlDataReader dr = SqlHelper.ExecuteReader(
                                                        SqlHelper.database,
                                                        CommandType.Text,
                                                        "select top 1 * from [SysConfig]"
                                                        );
            SysConfig Info = null;
            while (dr.Read())
            {
                Info = new SysConfig();
                Info.BaiduPage = Convert.ToInt32(dr["BaiduPage"]);
                Info.BaiduDay = Convert.ToInt32(dr["BaiduDay"]);
                Info.AccountDay = Convert.ToInt32(dr["AccountDay"]);
                Info.NewsFirstMomey =Convert.ToDouble(dr["NewsFirstMomey"]);
                Info.NewsSecondMomey = Convert.ToDouble(dr["NewsSecondMomey"]);
                Info.LinkFirstMomey = Convert.ToDouble(dr["LinkFirstMomey"]);
                Info.LinkSecondMomey = Convert.ToDouble(dr["LinkSecondMomey"]);
                Info.OurWebMomey = Convert.ToDouble(dr["OurWebMomey"]);
                Info.LockNumber = Convert.ToInt32(dr["LockNumber"]);
            }
            dr.Close();
            return Info;
        }

        /// <summary>
        /// 修改配置
        /// </summary>
        /// <param name="Info"></param>
        /// <returns></returns>
        public bool Update(SysConfig Info)
        {
            string strSql = "update [SysConfig] set [BaiduPage]=@BaiduPage,[BaiduDay]=@BaiduDay,[AccountDay]=@AccountDay,[NewsFirstMomey]=@NewsFirstMomey,[NewsSecondMomey]=@NewsSecondMomey,[LinkFirstMomey]=@LinkFirstMomey,[LinkSecondMomey]=@LinkSecondMomey,[OurWebMomey]=@OurWebMomey,[LockNumber]=@LockNumber";
            List<SqlParameter> parms = new List<SqlParameter>();
            parms.Add(new SqlParameter("@BaiduPage", Info.BaiduPage));
            parms.Add(new SqlParameter("@BaiduDay", Info.BaiduDay));
            parms.Add(new SqlParameter("@AccountDay", Info.AccountDay));
            parms.Add(new SqlParameter("@NewsFirstMomey", Info.NewsFirstMomey));
            parms.Add(new SqlParameter("@NewsSecondMomey", Info.NewsSecondMomey));
            parms.Add(new SqlParameter("@LinkFirstMomey", Info.LinkFirstMomey));
            parms.Add(new SqlParameter("@LinkSecondMomey", Info.LinkSecondMomey));
            parms.Add(new SqlParameter("@OurWebMomey", Info.OurWebMomey));
            parms.Add(new SqlParameter("@LockNumber", Info.LockNumber));
            return SqlHelper.ExecuteNonQuery(SqlHelper.database, CommandType.Text, strSql, parms.ToArray()) > 0;
        }
    }
}
